package com.ruoyi.zy.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zy.domain.VmeYian;
import com.ruoyi.zy.service.IVmeYianService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 医案Controller
 * 
 * @author ruoyi
 * @date 2024-04-17
 */
@Controller
@RequestMapping("/zy/yian")
public class VmeYianController extends BaseController
{
    private String prefix = "zy/yian";

    @Autowired
    private IVmeYianService vmeYianService;

    @RequiresPermissions("zy:yian:view")
    @GetMapping()
    public String yian()
    {
        return prefix + "/yian";
    }

    /**
     * 查询医案列表
     */
    @RequiresPermissions("zy:yian:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VmeYian vmeYian)
    {
        startPage();
        List<VmeYian> list = vmeYianService.selectVmeYianList(vmeYian);
        return getDataTable(list);
    }

    /**
     * 导出医案列表
     */
    @RequiresPermissions("zy:yian:export")
    @Log(title = "医案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VmeYian vmeYian)
    {
        List<VmeYian> list = vmeYianService.selectVmeYianList(vmeYian);
        ExcelUtil<VmeYian> util = new ExcelUtil<VmeYian>(VmeYian.class);
        return util.exportExcel(list, "医案数据");
    }

    /**
     * 新增医案
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存医案
     */
    @RequiresPermissions("zy:yian:add")
    @Log(title = "医案", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VmeYian vmeYian)
    {
        return toAjax(vmeYianService.insertVmeYian(vmeYian));
    }

    /**
     * 修改医案
     */
    @RequiresPermissions("zy:yian:edit")
    @GetMapping("/edit/{yianId}")
    public String edit(@PathVariable("yianId") Long yianId, ModelMap mmap)
    {
        VmeYian vmeYian = vmeYianService.selectVmeYianByYianId(yianId);
        mmap.put("vmeYian", vmeYian);
        return prefix + "/edit";
    }

    /**
     * 修改保存医案
     */
    @RequiresPermissions("zy:yian:edit")
    @Log(title = "医案", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VmeYian vmeYian)
    {
        return toAjax(vmeYianService.updateVmeYian(vmeYian));
    }

    /**
     * 删除医案
     */
    @RequiresPermissions("zy:yian:remove")
    @Log(title = "医案", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(vmeYianService.deleteVmeYianByYianIds(ids));
    }
}
